<template>
  <div class="ssc-list org-person-list">
    <div class="content">
      <div class="ssc-search">
        <a-form autocomplete="off">
          <a-row :gutter="24">
            <a-col :span="8">
              <a-form-item label="合约ID：">
                <a-input v-model:value="searchParam.id" placeholder="请输入" :maxlength="50" allowClear />
              </a-form-item>
            </a-col>
            <a-col :span="8">
              <a-form-item label="更新日期：">
                <a-range-picker allowClear @change="panelChange" v-model:value="timeRange" show-time format="YYYY-MM-DD HH:mm:ss" />
              </a-form-item>
            </a-col>

            <a-col :span="4" :offset="4">
              <a-row justify="end">
                <a-button @click="clear()">重置</a-button>
                <a-button class="ml-4" type="primary" @click="search()">查询</a-button>
              </a-row>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <div class="ssc-table">
        <div class="ssc-table-header">
          <span class="ssc-table-header-title">合约记录</span>
        </div>
        <a-table :columns="table.columns" :data-source="dataList" :loading="loading" :pagination="false" />

        <SimplePagination v-model:currentPage="pagination.current" :lastResponseSize="pagination.currentSize" />
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
  import { PlusCircleOutlined, PlusOutlined } from '@ant-design/icons-vue'
  import type { SelectProps } from 'ant-design-vue'
  import { message } from 'ant-design-vue'
  import type { Dayjs } from 'dayjs'
  import { onMounted, reactive, ref, watch } from 'vue'
  import { useRouter } from 'vue-router'

  import { requestContractRecordListByPage } from '/@/api/business/space'
  import { HttpCodeEnum } from '/@/enums/httpEnum'
  import { ServiceType, ServiceTypeDesc, ServiceTypeList } from '/@/enums/serviceEnum'
  import { CatalogTypeList } from '/@/enums/spaceEnum'
  import SimplePagination from '/@/views/main/dataSpace/component/SimplePagination.vue'
  const router = useRouter()
  type RangeValue = [Dayjs, Dayjs]
  const timeRange = ref<RangeValue>()
  const variable = reactive({
    category: {},
  })

  // 列表数据
  const dataList = ref()

  const loading = ref(false)

  // 服务类型列表
  const classification = ref<SelectProps['options']>([])

  /** 查询条件 */
  const searchParam = reactive({
    id: '',
    startTime: '',
    endTime: '',
  })

  /** 表格配置 */
  const table = reactive({
    columns: [
      { title: 'SSCID', dataIndex: 'sscId' },
      { title: '合约ID', dataIndex: 'id' },
      { title: '资产ID', dataIndex: 'assetId' },
      { title: '签约时间', dataIndex: 'CreatedTime', customRender: ({ record }) => record?.createdTime?.replace('T', ' ') || '--' },
    ],
  })

  /**
   * 重置
   */
  const clear = () => {
    searchParam.id = ''
    searchParam.startTime = ''
    searchParam.endTime = ''
    timeRange.value = undefined
    search()
  }

  // 分页配置自定义分液器
  const pagination = reactive({
    current: 1,
    currentSize: 10,
  })

  /**
   * 查询列表
   */
  const queryList = (params = {}) => {
    loading.value = true
    params.pageIndex = pagination.current
    params.startTime = searchParam.startTime
    params.endTime = searchParam.endTime
    params.id = searchParam.id
    requestContractRecordListByPage(params).then((res) => {
      loading.value = false
      if (res.responseCode === HttpCodeEnum.SUCCESS) {
        pagination.currentSize = res.responseData.list.length
        dataList.value = res.responseData.list
      }
    })
  }

  watch(
    () => pagination.current,
    () => {
      queryList()
    },
  )

  /**
   * 查询
   */
  const search = () => {
    queryList({ current: 1 })
  }

  const panelChange = (value, mode) => {
    console.log(value, mode)
    searchParam.startTime = mode[0]
    searchParam.endTime = mode[1]
  }

  onMounted(() => {
    queryList({ current: 1 })
  })
</script>

<style lang="less" scoped>
  .org-person-list {
    display: flex;
  }

  .org {
    width: 200px;
    height: 100%;
    padding: 18px;
    background: #fff;

    .org-title {
      margin-bottom: 12px;
      font-weight: bold;
      display: flex;
      justify-content: space-between;
      align-items: center;

      .anticon-plus-circle {
        cursor: pointer;
        color: #08979c;
      }
    }

    .classification {
      height: 40px;
      width: 100%;
      line-height: 40px;
      padding: 0 4px;
      display: flex;
      justify-content: space-between;
      cursor: pointer;

      &.active {
        background: #cbf4f6;
        color: #08979c;
      }

      &:hover {
        background: #cbf4f6;
        color: #08979c;

        .action {
          // display: block;
          display: inline-block;
          min-width: 89px;
        }
      }

      .action {
        display: none;
        color: #08979c;
        font-size: 12px;
        text-align: right;

        > span {
          margin-left: 4px;
        }
        // .edit {
        // }

        .del {
          color: #f5222d;
        }
      }
    }
  }

  .content {
    flex: 1;
  }

  .ssc-search {
    margin-left: 16px;
    padding-bottom: 24px;
  }

  .ssc-table {
    margin-left: 16px;
    padding-bottom: 10px;

    .dept-leader {
      position: relative;
      top: -2px;
      height: 20px;
      margin-right: 4px;
      padding: 0 8px;
      border: none;
      font-size: 10px;
      background: #87d068;
    }
  }
</style>
